//
//  Mail_SignLst_Task.m
//  EpointFrame5
//
//  Created by wangzhigang on 14-5-20.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "Mail_SignLst_Task.h"
#import "SignInfoModel.h"

@implementation Mail_SignLst_Task
-(void)execute
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *ValidateData = [EpointBizTools getToken];
    NSString *url = self.getMobileOAWebserviceURL;
    NSString *wsNamespace = NSLocalizedString(@"Epoint_DNet_WS_NameSpace", @"");
    
    NSString *userguid = [userDefaults objectForKey:Epoint_User_UserGuid];
    NSString *mailguid = [params objectForKey:@"MailGuid"];
     EpointWebServiceUtil *webserviceHelper = [[EpointWebServiceUtil alloc]initWithUrl:url namespace:wsNamespace method:@"Mail_SignLst"];
    NSString *ParasXml = @"<![CDATA[<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><UserGuid>%@</UserGuid><MailGuid>%@</MailGuid></paras>]]>";
    ParasXml = [NSString stringWithFormat:ParasXml,userguid,mailguid];
//    ParasXml = [StringUtil filterXmlString:ParasXml];
    [webserviceHelper addParameterForString:@"ValidateData" value:ValidateData];
    [webserviceHelper addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs = webserviceHelper.start;
    NSMutableArray *result = [self validateXMLWS2:bs];
    NSString *msg = [result objectAtIndex:1];
    if ([[result objectAtIndex:0]isEqualToString:@"1"]) {
        [self sendDataRefreshUI:bs];
    }
    else
    {
        [self exeFailureWithMessage:msg];
    }

}

+(NSMutableArray *)getList:(NSString *)_xml
{
    _xml = [EpointStringUtil getXMLFormatedAttributeBsWithTag:_xml xmlTag:@"SignList"];
    
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString:_xml  options:0 error:nil];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *arrays = [rootElement elementsForName:@"SignInfo"];
    NSMutableArray *listmp = [[NSMutableArray alloc]init];
    
    for (GDataXMLElement *arr in arrays)
    {
        SignInfoModel *m = [[SignInfoModel alloc]init];
        GDataXMLElement *SignUserDispName = [[arr elementsForName:@"SignUserDispName"] objectAtIndex:0];
        m.SignUserDispName = [SignUserDispName stringValue];
        
        GDataXMLElement *SignUserGuid = [[arr elementsForName:@"SignUserGuid"] objectAtIndex:0];
        m.SignUserGuid = [SignUserGuid stringValue];
        
        GDataXMLElement *DeptName = [[arr elementsForName:@"DeptName"] objectAtIndex:0];
        m.DeptName = [DeptName stringValue];
        
        GDataXMLElement *TelephoneOffice = [[arr elementsForName:@"TelephoneOffice"] objectAtIndex:0];
        m.TelephoneOffice = [TelephoneOffice stringValue];
        
        GDataXMLElement *SignDate = [[arr elementsForName:@"SignDate"] objectAtIndex:0];
        m.SignDate = [SignDate stringValue];
        
        [listmp addObject:m];
        
    }
    
    return listmp ;
}

@end
